<template>
  <div class="wrapper">
    <!-- 单图片 -->
    <div
      class="single"
      v-if="postData.images.length > 0 && postData.images.length < 3"
    >
      <div class="left">
        <img :src="postData.images[0]" alt="" />
      </div>
      <div class="right">
        <div class="title">
          {{ postData.title }}
        </div>
        <div class="content">
          {{ postData.summary | myFilter }}
        </div>
        <div class="post_info">
          <div class="info_item">
            <span class="el-icon-location-outline">{{
              postData.cityName
            }}</span>
            <span class="author">
              by
              <img
                :src="$axios.defaults.baseURL + postData.account.defaultAvatar"
                alt=""
              />
              <span
                class="author_name"
                @click.stop="$router.push('/user/personal')"
                >{{ postData.account.nickname }}</span
              >
            </span>
            <span class="el-icon-view"> {{ postData.watch }}</span>
          </div>
          <div class="like" v-if="postData.like">{{ postData.like }} 赞</div>
          <div class="like" v-else>没人赞</div>
        </div>
      </div>
    </div>
    <!-- 多图片 -->
    <div class="multip" v-if="postData.images.length >= 3">
      <div class="title">{{ postData.title }}</div>
      <div class="content">
        {{ postData.summary | myFilter }}
      </div>
      <div class="multip_img">
        <img :src="postData.images[0]" alt="" />
        <img :src="postData.images[1]" alt="" />
        <img :src="postData.images[2]" alt="" />
      </div>
      <div class="post_info">
        <div class="info_item">
          <span class="el-icon-location-outline"> {{ postData.cityName }}</span>
          <span class="author">
            by
            <img
              :src="$axios.defaults.baseURL + postData.account.defaultAvatar"
              alt=""
            />
            <span
              class="author_name"
              @click.stop="$router.push('/user/personal')"
              >{{ postData.account.nickname }}</span
            >
          </span>
          <span class="el-icon-view"> {{ postData.watch }}</span>
        </div>
        <div class="like" v-if="postData.like">{{ postData.like }} 赞</div>
        <div class="like" v-else>没人赞</div>
      </div>
    </div>
    <!-- 没有图片 -->
    <div class="none_img" v-if="!postData.images.length">
      <div class="title">
        {{ postData.title }}
      </div>
      <div class="content">
        {{ postData.summary | myFilter }}
      </div>
      <div class="post_info">
        <div class="info_item">
          <span class="el-icon-location-outline">{{ postData.cityName }}</span>
          <span class="author">
            by
            <img
              :src="$axios.defaults.baseURL + postData.account.defaultAvatar"
              alt=""
            />
            <span
              class="author_name"
              @click.stop="$router.push('/user/personal')"
              >{{ postData.account.nickname }}</span
            >
          </span>
          <span class="el-icon-view"> {{ postData.watch }}</span>
        </div>
        <div class="like" v-if="postData.like">{{ postData.like }} 赞</div>
        <div class="like" v-else>没人赞</div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: ["postData"],
  filters: {
    // 优化简略内容的显示
    myFilter(oldTaxt) {
      return oldTaxt.replace(/&nbsp;/g, " ");
    },
  },
};
</script>

<style lang="less" scoped>
.wrapper {
  padding: 20px 0;
  border-bottom: 1px solid #eee;
  cursor: pointer;
  .title,
  .content {
    // 设置文字不可复制
    user-select: none;
  }
  .single {
    display: flex;
    .left {
      img {
        width: 220px;
        height: 150px;
        object-fit: cover;
      }
    }
    .right {
      flex: 1;
      height: 150px;
      margin-left: 10px;
      .title {
        font-size: 18px;
        margin-bottom: 8px;
        // white-space: nowrap;
        &:hover {
          color: orange;
        }
      }
      .content {
        height: 64px;
        line-height: 1.5;
        font-size: 14px;
        color: #666;
        margin-bottom: 10px;
        // 设置多行文本省略
        overflow: hidden;
        display: -webkit-box;
        -webkit-line-clamp: 3;
        -webkit-box-orient: vertical;
        text-overflow: ellipsis;
      }
      .post_info {
        display: flex;
        justify-content: space-between;
        align-items: center;
        .info_item {
          // display: flex;
          span {
            font-size: 12px;
            color: #999;
            margin-right: 10px;
          }
          .author {
            img {
              width: 16px;
              height: 16px;
              border-radius: 50%;
              object-fit: cover;
              vertical-align: bottom;
              margin-left: 4px;
            }
            .author_name {
              color: orange;
            }
          }
        }
        .like {
          font-size: 16px;
          color: orange;
        }
      }
    }
  }

  .multip {
    .title {
      font-size: 18px;
      margin-bottom: 8px;
      // white-space: nowrap;
      &:hover {
        color: orange;
      }
    }
    .content {
      height: 64px;
      line-height: 1.5;
      font-size: 14px;
      color: #666;
      margin-bottom: 15px;
      // 设置多行文本省略
      overflow: hidden;
      display: -webkit-box;
      -webkit-line-clamp: 3;
      -webkit-box-orient: vertical;
      text-overflow: ellipsis;
    }
    .multip_img {
      display: flex;
      justify-content: space-between;
      margin-bottom: 20px;
      img {
        width: 220px;
        height: 150px;
        object-fit: cover;
      }
    }
    .post_info {
      display: flex;
      justify-content: space-between;
      align-items: center;
      .info_item {
        // display: flex;
        span {
          font-size: 12px;
          color: #999;
          margin-right: 10px;
        }
        .author {
          img {
            width: 16px;
            height: 16px;
            border-radius: 50%;
            object-fit: cover;
            vertical-align: bottom;
            margin-left: 4px;
          }
          .author_name {
            color: orange;
          }
        }
      }
      .like {
        font-size: 16px;
        color: orange;
      }
    }
  }
  .none_img {
    .title {
      font-size: 18px;
      margin-bottom: 8px;
      // white-space: nowrap;
      &:hover {
        color: orange;
      }
    }
    .content {
      height: 64px;
      line-height: 1.5;
      font-size: 14px;
      color: #666;
      margin-bottom: 15px;
      // 设置多行文本省略
      overflow: hidden;
      display: -webkit-box;
      -webkit-line-clamp: 3;
      -webkit-box-orient: vertical;
      text-overflow: ellipsis;
    }
    .post_info {
      display: flex;
      justify-content: space-between;
      align-items: center;
      .info_item {
        // display: flex;
        span {
          font-size: 12px;
          color: #999;
          margin-right: 10px;
        }
        .author {
          img {
            width: 16px;
            height: 16px;
            border-radius: 50%;
            object-fit: cover;
            vertical-align: bottom;
            margin-left: 4px;
          }
          .author_name {
            color: orange;
          }
        }
      }
      .like {
        font-size: 16px;
        color: orange;
      }
    }
  }
}
</style>